package com.hxzy.controller.userinfo;

import com.alibaba.fastjson.JSONObject;
import com.hxzy.common.BaseServlet;
import com.hxzy.common.ResultAjax;
import com.hxzy.entity.UserInfo;
import com.hxzy.service.UserInfoService;
import com.hxzy.service.impl.UserInfoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description:
 * @Author: ykj
 * @Date: 2022/3/2 9:31
 */

@WebServlet(urlPatterns = "/jsonDelete/user")
public class DeleteJsonServlet extends BaseServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("UTF-8");
        UserInfo userInfo = super.CollectiongParameterToJSON(req, UserInfo.class);


            UserInfoService service=new UserInfoServiceImpl();
            int delete = service.delete(userInfo.getId());
            ResultAjax resultAjax;
            if (delete>0){
                resultAjax=ResultAjax.success("删除成功");
            }else {
                resultAjax=ResultAjax.error("删除失败");
            }
            super.render(resp, JSONObject.toJSONString(resultAjax));

    }
}
